package 第3节函数;

public class LianXi02 {
    public static void main(String[] args) {
        System.out.println(isPalindrome(123));
        System.out.println(isPalindrome(12321));
    }
    public static int reverse(int num) {
        /*
        1234 % 10 = 4   0*10 + 4 = 4
        123 % 10 = 3    4*10 + 3 = 43
        12 % 10 = 2     43*10 + 2 = 432
        1 % 10 = 1      432*10 + 1 = 4321
        0
        */
        int pre = 0;
        while (num != 0) {
            pre = pre * 10 + num % 10;
            num /= 10;
        }
        return pre;
    }
    public static boolean isPalindrome(int num) {
        /*
        1234 != 4321
        12321 == 12321
        */
        int reverseNum = reverse(num);
        return reverseNum == num;
    }
}
